<?php

namespace App\Util;

use Carbon\Carbon;
use Illuminate\Support\Str;

class Help
{
    public static function compressDate($date)
    {
        // Step 1: Convert the date to a timestamp
        $timestamp = Carbon::parse($date)->timestamp;

        // Step 2: Hash the timestamp
        $hashed = hash('crc32', $timestamp, false);

        // Step 3: Convert the hashed value to a base 36 string (0-9, a-z)
        $base36 = base_convert($hashed, 16, 36);

        // Step 4: Ensure the result is exactly 3 characters long
        // Pad with zeros or trim as necessary
        $compressed = substr(str_pad($base36, 3, '0', STR_PAD_LEFT), 0, 3);

        return $compressed;
    }

    public static function generateSampleSn()
    {
        return self::compressDate(date('Y-m-d')) . strtolower(Str::random(5));
    }
}
